<!DOCTYPE html>
<html>
<head>
    {include file='public/meta'/}

    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrapSwitch.css">
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/setyxhd.css?v=5"/>
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/fonts/css/font-awesome.css?v=3"/>

    
    <script src="__STATIC_URL__/static/js/bootstrapSwitch.js"></script>


    <style>
        .checkbox input[type="checkbox"], .checkbox input[type="radio"] {
            width: 18px;
            height: 18px;
            margin-top: 1px;
        }
        .gift-record{
            width: 80%;
            display:inline-block;
        }
        .gift-record select, .gift-record input {
            display: inline-block;
            width: 65%;
            float: left;
        }
    </style>
</head>
<body id="body">
{include file='public/header'/}
<!------------------导航-------------------------->
<section>
    {include file='public/left'/}
    <!--------------------------主要内容区域------------------------------------->
    <div class="content">
        <div class="panel  ">
            <div class="panel-body">
                <!--路径导航-->
                <ol class="breadcrumb">
                    <li>当前位置是:</li>
                    <li><a href="{:url('cardus/cardinfo',['card_id'=>$card['card_id']])}">会员卡管理</a></li>
                    <li class="active">分享设置</li>
                </ol>
                <!--创建会员卡主要内容-->
                <div class="card-content mgl15 mgr15 clearfix">
                    <div class="panel panel-default ng-scope">
                        <div class="panel-heading">
                            会员卡分享规则
                        </div>
                        <div class="panel-body">
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <td>分享标题</td>
                                    <td>赠送积分</td>
                                    <td>赠送余额</td>
                                    <td>赠送卡券</td>
                                    <td>当前状态</td>
                                    <td>创建时间</td>
                                    <td class="text-center">操作</td>
                                </tr>
                                </thead>
                                <tbody>
                                {volist name="list" id="vo"}
                                <tr ng-if="!instances.list.length" class="ng-scope">
                                    <td>{$vo.title}</td>
                                    <td>{$vo.reward_bonus}</td>
                                    <td>{$vo.reward_balance}</td>
                                    <td>{$vo.zs_card_info}</td>
                                    <td>
                                        <a class="btn-link"
                                           href="{:url('marke/statushare',['id'=>$vo['id'],'statu'=>$vo['statu'],'card_id'=>$card['card_id']])}">
                                            {switch name="vo.statu"}
                                            {case value="1"}已关闭{/case}
                                            {case value="0"}已开启{/case}
                                            {default /}未知
                                            {/switch}
                                        </a>
                                    </td>
                                    <td>{$vo.create_time}</td>
                                    <td>
                                        <a class="btn-link"
                                           href="{:url('marke/sharecount',['id'=>$vo['id'],'card_id'=>$card['card_id']])}">
                                            绩效查看
                                        </a>
                                        {if condition="checkPath('marke/delshare')"}
                                        <a class="btn-link"
                                           href="{:url('marke/delshare',['id'=>$vo['id'],'card_id'=>$card['card_id']])}">
                                            | 删除
                                        </a>
                                        {/if}
                                    </td>
                                </tr>
                                {/volist}
                                </tbody>
                            </table>
                            {notempty name="card.sharelink"}
                            <div class="alert alert-info" role="alert">分享链接：{$card.sharelink}</div>
                            {/notempty}
                        </div>
                    </div>
                    <!--创建会员卡主要内容-->
                    <div class="panel panel-default ng-scope c_content">
                        <div class="headings gengduoxian">
                            <i class="infoLine"></i>会员卡分享配置
                        </div>

                        <form class="form-horizontal " action="" method="post"  id="creatcards">
                            <input name="card_id" type="hidden" value="{$card['card_id']}">
                            <div class="panel-body">

                                <div class="form-horizontal ng-scope" data-label="分享标题" data-layout="horizontal">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label ng-binding">分享标题</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="title" id="title" placeholder=""
                                                   value="{$info.title}" required="required">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-horizontal ng-scope" data-label="分享描述">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label ng-binding">分享描述</label>
                                        <div class="col-sm-10">
                                            <textarea class="form-control" style="resize: none;" id="description" rows="4" maxlength="32"
                                                      name="description" placeholder="" required="required">{$info.description}</textarea>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-horizontal" data-layout="horizontal">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">活动奖品</label>
                                        <div class="col-sm-10">

                                            <div style=" margin-top:3px;">
                                                <div class="checkbox checkbox-info checkbox-inline prize">
                                                    <input type="hidden" id="isbonus" value="{$info['is_bonus']}" name="is_bonus">
                                                    <input type="checkbox" id="bonus" class="gift-input">
                                                    <label for="bonus"> 奖励积分 </label>
                                                    <span class="container" style="display:none;">
    							                                <div class="col-md-6 pannel charge-rule-box"
                                                                     style="float:none;margin-top:10px;margin-left: -22px;width: 400px;">

                                                                    <div style="margin-top:10px;" class="gift-record">

    											                          <input type="number"
                                                                                 class="form-control prize-gift" min="1"
                                                                                 onkeyup="this.value=this.value.replace(/\D/g,&#39;&#39;)"
                                                                                 style="width: 80px;margin-left: 3px;display: inline-block;"
                                                                                 placeholder="请填写" name="reward_bonus"
                                                                                 value="{$info.reward_bonus}">
                                                                          <span style=" margin-left: 75px;line-height:38px;">积分</span>
                                                                          <a href="javascript:void(0);"
                                                                             class="del-charge-btn"
                                                                             style="display:none;"><i
                                                                                  class="icon-close"></i>
                                                                          </a>
                                                                    </div>
    							                				</div>
    								                         </span>
                                                </div>
                                                <div class="checkbox checkbox-info checkbox-inline prize">
                                                    <input type="hidden" id="isbalance" value="{$info['is_balance']}" name="is_balance">
                                                    <input type="checkbox" id="balance" class="gift-input">
                                                    <label for="balance"> 奖励储值 </label>
                                                    <span class="container" style="display:none;">
    							                                <div class="col-md-6 pannel charge-rule-box"
                                                                     style="float:none;margin-top:10px;margin-left: -22px;width: 400px;">

                                                                    <div style="margin-top:10px;" class="gift-record">

    											                          <input type="number"
                                                                                 class="form-control prize-gift" min="1"
                                                                                 onkeyup="this.value=this.value.replace(/\D/g,&#39;&#39;)"
                                                                                 style="width: 80px;margin-left: 3px;display: inline-block;"
                                                                                 placeholder="请填写" name="reward_balance"
                                                                                 value="{$info.reward_balance}">
                                                                          <span style=" margin-left: 75px;line-height:38px;">元</span>
                                                                          <a href="javascript:void(0);"
                                                                             class="del-charge-btn"
                                                                             style="display:none;"><i
                                                                                  class="icon-close"></i>
                                                                          </a>
                                                                    </div>
    							                				</div>
    								                         </span>
                                                </div>
                                                <div class="checkbox checkbox-info checkbox-inline prize">
                                                    <input type="hidden" id="iscards" value="{$info['is_cards']}"
                                                           name="is_cards">
                                                    <input type="checkbox" id="cards" class="gift-input">
                                                    <label for="cards"> 赠送优惠券 </label>
                                                    <span class="container " style="display:none;" coupontype="0">
   <a href="javascript:;" data-counts="1" id="datacount"
      style="color: #2db7f5;font-size: 13px;">添加赠送</a>
                                                            <div class="col-xs-10 col-sm-10 col-md-10 form1">

                                        </div>
                                                            </span>
                                                </div>

                                            </div>

                                        </div>
                                    </div>
                                </div>
                                <!--<div class="form-horizontal ng-scope" data-label="奖励积分" data-layout="horizontal">-->
                                <!--<div class="form-group">-->
                                <!--<label class="col-sm-2 control-label">奖励积分</label>-->
                                <!--<div class="col-sm-10">-->
                                <!--<input type="text" class="form-control" name="reward_bonus" placeholder=""-->
                                <!--value="{$info.reward_bonus}">-->
                                <!--<div class="r-desc ng-binding ng-scope">被推荐人开卡后，推荐人奖励对应积分</div>-->
                                <!--</div>-->
                                <!--</div>-->
                                <!--</div>-->
                                <!--<div class="form-horizontal ng-scope" data-label="奖励储值" data-layout="horizontal">-->
                                <!--<div class="form-group">-->
                                <!--<label class="col-sm-2 control-label ng-binding">奖励储值</label>-->
                                <!--<div class="col-sm-10">-->
                                <!--<input type="text" class="form-control" name="reward_balance" placeholder=""-->
                                <!--value="{$info.reward_balance}">-->
                                <!--<div class="r-desc ng-binding ng-scope">被推荐人开卡后，推荐人奖励对应储值，单位元-->
                                <!--</div>-->
                                <!--</div>-->
                                <!--</div>-->
                                <!--</div>-->
                                <div class="form-horizontal ng-scope" data-label="详细说明">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label ng-binding">详细说明</label>
                                        <div class="col-sm-10">
                                            <textarea class="form-control" style="resize: none;" rows="4" name="content"
                                                      placeholder="" id="content">{$info.content}</textarea>
                                            <div class="r-desc ng-binding ng-scope">被推荐人打开页面后将显示此说明</div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-horizontal ng-scope" data-label="自动到账">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label ng-binding">自动到账</label>
                                        <div class="col-sm-10">
                                            <div class="switch" id="hurry">
                                                <input type="checkbox" {if condition="$info['is_account'] eq '1' "
                                                       }checked{/if}/>
                                                <input type="hidden" name="is_account" id="is_account"
                                                       value="{$info['is_account']}">
                                            </div>
                                            <div class="r-desc ng-binding ng-scope">开启后推荐人的奖励会自动到账</div>
                                        </div>

                                    </div>
                                </div>

                                <div class="form-horizontal ng-scope" data-label="开启通知">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label ng-binding">开启通知</label>
                                        <div class="col-sm-10">
                                            <div class="switch" id="notice">
                                                <input type="checkbox" {if condition="$info['is_notice'] eq 'Y' "
                                                       }checked{/if}/>
                                                <input type="hidden" name="is_notice" id="is_notice"
                                                       value="{$info['is_notice']}">
                                            </div>
                                            <div class="r-desc ng-binding ng-scope">开启后推荐人的奖励会通过微信公众号接受到通知</div>
                                        </div>

                                    </div>
                                </div>

                            </div>
                            <div class="panel-footer">
                                <input type="hidden" name="id" id="cid" value="{$info['id']}">
                                <button class="btn btn-success" type="button" id="creatcards-btn">保存</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        {include file='public/footer'/}
    </div>
</section>
</body>
<script src="__STATIC_URL__/static/js/setyxhd.js?v=2"></script>

<script>
    $("#hurry").on('switch-change', function (e, data) {
        var $el = $(data.el), value = data.value;
        if (value == true) {
            $("#is_account").val(1);
        } else {
            $("#is_account").val(0);
        }
    });
    $("#notice").on('switch-change', function (e, data) {
        var $el = $(data.el), value = data.value;
        if (value == true) {
            $("#is_notice").val("Y");
        } else {
            $("#is_notice").val("N");
        }
    });
    $(function(){
        var permanent_ck="{$info['time_type']}";
        if(permanent_ck==""){
            $("#permanent_ck").prop("checked", true)
        }
        if(permanent_ck=="range"){
            $(".data_ipt").removeAttr("disabled");
            $("#permanent_ck").prop("checked", false)
        }else if(permanent_ck=="lasting"){
            $(".data_ipt").attr("disabled", "disabled");
            $("#permanent_ck").prop("checked", true)
        }


        var is_balance="{$info['is_balance']}";
        var $balance = $("#balance").parent().find(".container");
        var is_bonus="{$info['is_bonus']}";
        var $bonus = $("#bonus").parent().find(".container");
        var is_cards="{$info['is_cards']}";
        var $cards = $("#cards").parent().find(".container");
        if(is_bonus=="Y"){
            $("#bonus").prop("checked", true)
            $bonus.show();
        }
        if(is_cards=="Y"){
            $("#cards").prop("checked", true)
            $cards.show();
        }
        if(is_balance=="Y"){
            $("#balance").prop("checked", true)
            $balance.show();
        }

    });
</script>
<script>

    $(function(){
        var id=$("#cid").val();
        $.ajax({
            url: "{:url('marke/getsharecardslist')}",
            type: "post",
            data: {id:id},
            success: function (data) {
                console.log(1, data);
                var text = data;
                var html8=""
                for(var i=0; i<text.length; i++){
                    if(text[i].title==null){
                        html8=""
                    }else{
                        var html8 ='                        <div class="col-xs-12 col-sm-12 col-md-12 addcord" >\n' +
                            '                            <div class="gift-record">\n' +
                            '                                <select name="cardlist[zs_card_id][]"  class="form-control" >\n' +
                            '                                    <option value="'+text[i].card_id+'" data-title="'+text[i].title+' "data-limit="'+text[i].get_limit+'">'+text[i].title+'  ( 最大可选卡券数量为'+text[i].get_limit+')</option>\n' +
                            '                                     </select>\n' +
                            '                                <input type="number" class="form-control" min="1" style="width:20%;" placeholder="请填写" value="'+text[i].zs_no+'" name="cardlist[zs_no][]"><span style="line-height:35px;">张</span>\n' +
                            '                            </div>\n' +
                            '                             <a href="javascript:;" onclick="delsel(this)" style="font-size: 13px; display:inline-block; ">删除</a>\n' +
                            '                    </div>';
                    }
                    $('.form1').append(html8)
                }

            }
        })
        $.ajax({
            url: "{:url('cards/getcardlist')}",
            type:"post",
            data: {
            },
            success: function (data) {
                console.log(1,data);
                var text =data.data;
                //console.log(text);
                var option2="";
                for(var i=0; i<text.length; i++){
                    // console.log(text[i].card_id);

                    option2 +='<option value="'+text[i].card_id+'" data-title="'+text[i].title+' "data-limit="'+text[i].get_limit+'">'+text[i].title+'  ( 最大可选卡券数量为'+text[i].get_limit+' )</option>\n'

                }
                $('#sel1').find("select").append(option2);
                $("#opt").change(function(){

                    limit=parseInt($("#sel1").find("option:selected").attr("data-limit"));
                    var nu=parseInt($("#num").val());

                    $("#num").attr("max",limit);




                });

                $("#datacount").click(function(){


                    datacount=$(this).attr('data-counts');
                    get_limit=parseInt($("#sel"+datacount).find("option:selected").attr("data-limit"));
                    num=parseInt($("#sel"+datacount).find("input").val());
                    val=$("#sel"+datacount).find("option:selected").val();
                    if( $("#sel"+datacount).find("option:selected").val()==""){
                        alert("卡券选项不能为空");
                        return;
                    }
                    else if(num>get_limit){
                        console.log(num,get_limit);
                        console.log(num>get_limit);
                        alert("你选择的卡券数量超过了该卡券的领取数量!");
                        return;
                    }
                    else{

                        datacount2=parseInt(datacount)+1;
                        $(this).attr('data-counts',datacount2);
                        var html1 ='                        <div class="col-xs-12 col-sm-12 col-md-12 addcord" >\n' +
                            '                            <div class="gift-record"id="sel'+datacount2+'">\n' +
                            '                                <select name="cardlist[zs_card_id][]"  class="form-control" >\n' +
                            '                                    <option value="" selected="selected">--请选择--</option>\n' ;

                        var html3= '                                </select>\n' +
                            '                                <input type="number" class="form-control" min="1" style="width:20%;" placeholder="请填写" value="1" name="cardlist[zs_no][]"><span style="line-height:35px;">张</span>\n' +
                            '                            </div>\n' +
                            '                             <a href="javascript:;" onclick="delsel(this)" style="font-size: 13px; display:inline-block; ">删除</a>\n' +
                            '                    </div>';

                        $('.form1').append(html1+option2+html3);

                        $("#sel"+datacount2).find("select").change(function(){

                            limit=$("#sel"+datacount2).find("option:selected").attr("data-limit");
                            $("#sel"+datacount2).find("input").attr("max",limit);



                        });

                    }




                })
            }
        })


    })
</script>
<script>
    $("#creatcards-btn").click(function(){
        var title=$("#title").val();
        var description=$("#description").val();
        var content=$("#content").val();

        var items = document.getElementsByTagName('select'),
            len = items.length,
            i = 0,
            valMap = {},
            sel,
            val;

        // 遍历并保存各个下拉列表的值于valMap
        for(; i < len; i++){
            sel = items[i];
            val = sel.options[sel.selectedIndex].value;

            // 没有相同的取值时保存该值，否则返回false
            if(!valMap[val]){
                valMap[val] = 1;
            }else{
                layer.msg('请删除重复的卡券！');
                return false;
            }

        }

        if(title==""){
            layer.msg('请填写分享标题！');
            return false;
        }
        if(description==""){
            layer.msg('请填写分享描述！');
            return false;
        }

        if(content==""){
            layer.msg('请填写详细说明！');
            return false;
        }

        $.ajax({
            url: "{:url('')}",
            type: "post",
            data: $("#creatcards").serialize(),
            success: function (data) {
                console.log(data);
                if(data.code==0){
                    layer.msg(data.message);
                    setTimeout(function(){
                        window.location.reload();

                    },1500)
                }else{
                    layer.msg(data.message);
                }
            }
        })

    })
</script>
</html>
